package com.hornsun.manage.homepage.api;

import com.hornsun.client.homepage.api.HomepageAPI;
import com.hornsun.database.IRedisService;
import com.hornsun.domain.dbo.ShowInfor;
import com.hornsun.manage.homepage.dto.MemberStatusDTO;
import com.hornsun.repository.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 编译中... on 2018/5/5.
 */
@RestController
@RequestMapping("/manage/homepage")
public class ManageHomepage {
    @Resource
    private IRedisService service;

    @Resource
    private MemberWechatRepository memberWechatRepository ;

    @Resource
    private OrderFormRepository orderFormRepository;

    @Resource
    private MaterialRepository materialManagementRepository;

    @Resource
    private HomepageAPI homepageAPI;

    @GetMapping("/getHomepageInfo")
    public ResponseEntity<?> getMemberStatus(){
        MemberStatusDTO memberStatusDTO = new MemberStatusDTO();
        memberStatusDTO.setHeadcount(memberWechatRepository.totalCount());
        memberStatusDTO.setOnline(service.count());
        memberStatusDTO.setTodayOrder(orderFormRepository.todayOrder());
        memberStatusDTO.setMaterialManagementList(materialManagementRepository.getLately());
        List<ShowInfor> showInforList = homepageAPI.getHomeRecommend();
        if (showInforList.size()>2){
            showInforList=showInforList.subList(0,2);
        }
        memberStatusDTO.setShowInforList(showInforList);
        return new ResponseEntity<Object>(memberStatusDTO, HttpStatus.OK);
    }
}
